package com.codeazur.as3swf.tags
{
   import com.codeazur.as3swf.SWFData;
   import com.codeazur.as3swf.data.consts.BitmapFormat;
   import flash.utils.ByteArray;
   
   public class TagDefineBitsLossless implements IDefinitionTag
   {
      
      public static const TYPE:uint = 20;
       
      
      public var bitmapFormat:uint;
      
      public var bitmapWidth:uint;
      
      public var bitmapHeight:uint;
      
      public var bitmapColorTableSize:uint;
      
      protected var _characterId:uint;
      
      protected var _zlibBitmapData:ByteArray;
      
      public function TagDefineBitsLossless()
      {
         super();
         this._zlibBitmapData = new ByteArray();
      }
      
      public function get characterId() : uint
      {
         return this._characterId;
      }
      
      public function set characterId(param1:uint) : void
      {
         this._characterId = param1;
      }
      
      public function get zlibBitmapData() : ByteArray
      {
         return this._zlibBitmapData;
      }
      
      public function parse(param1:SWFData, param2:uint, param3:uint, param4:Boolean = false) : void
      {
         this._characterId = param1.readUI16();
         this.bitmapFormat = param1.readUI8();
         this.bitmapWidth = param1.readUI16();
         this.bitmapHeight = param1.readUI16();
         if(this.bitmapFormat == BitmapFormat.BIT_8)
         {
            this.bitmapColorTableSize = param1.readUI8();
         }
         param1.readBytes(this.zlibBitmapData,0,param2 - (this.bitmapFormat == BitmapFormat.BIT_8?8:7));
      }
      
      public function publish(param1:SWFData, param2:uint) : void
      {
         var _loc3_:SWFData = new SWFData();
         _loc3_.writeUI16(this._characterId);
         _loc3_.writeUI8(this.bitmapFormat);
         _loc3_.writeUI16(this.bitmapWidth);
         _loc3_.writeUI16(this.bitmapHeight);
         if(this.bitmapFormat == BitmapFormat.BIT_8)
         {
            _loc3_.writeUI8(this.bitmapColorTableSize);
         }
         if(this._zlibBitmapData.length > 0)
         {
            _loc3_.writeBytes(this._zlibBitmapData);
         }
         param1.writeTagHeader(this.type,_loc3_.length,true);
         param1.writeBytes(_loc3_);
      }
      
      public function clone() : IDefinitionTag
      {
         var _loc1_:TagDefineBitsLossless = new TagDefineBitsLossless();
         _loc1_.characterId = this.characterId;
         _loc1_.bitmapFormat = this.bitmapFormat;
         _loc1_.bitmapWidth = this.bitmapWidth;
         _loc1_.bitmapHeight = this.bitmapHeight;
         if(this._zlibBitmapData.length > 0)
         {
            _loc1_.zlibBitmapData.writeBytes(this._zlibBitmapData);
         }
         return _loc1_;
      }
      
      public function get type() : uint
      {
         return TYPE;
      }
      
      public function get name() : String
      {
         return "DefineBitsLossless";
      }
      
      public function get version() : uint
      {
         return 2;
      }
      
      public function get level() : uint
      {
         return 1;
      }
      
      public function toString(param1:uint = 0, param2:uint = 0) : String
      {
         return Tag.toStringCommon(this.type,this.name,param1) + "ID: " + this.characterId + ", " + "Format: " + BitmapFormat.toString(this.bitmapFormat) + ", " + "Size: (" + this.bitmapWidth + "," + this.bitmapHeight + ")";
      }
   }
}
